package com.itsitio.dbloader.util;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;


/**
 * Parser
 * 
 * 
 */
public abstract class CSVParser {

	private int count;

	public CSVParser(File source) throws IOException {
		System.out.println("Persistiendo entidades del archivo:" + source.getName());
		count = 0;
		FileInputStream fstream = new FileInputStream(source);
		// Get the object of DataInputStream
		DataInputStream in = new DataInputStream(fstream);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		String strLine;
		// Read File Line By Line
		while ((strLine = br.readLine()) != null) {
			handleLine(strLine, count);
			count++;
		}
		// Close the input stream
		in.close();

		System.out.println("se persistieron exitosamente " + count + " entidades");

	}

	public abstract void handleLine(String line, int count);

	public int getCount() {
		return count;
	}
}
